package com.sangananitsolution.fragments;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Toast;

import com.sangananitsolution.gogoproject.R;

public class MySearch extends Fragment {
	
	Context context;
	// GPSTracker class
		GPSTracker gps;
		
	public MySearch(Context  container) {
		this.context=container;
	}
	
	public MySearch() {
		
	}
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.mysearch, container, false);

		view.findViewById(R.id.imgsearchMysearch).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub

						android.app.FragmentManager fragmentManager = getFragmentManager();
						android.app.FragmentTransaction fragmentTransaction = fragmentManager
								.beginTransaction();

						fragmentTransaction
								.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

						fragmentTransaction.addToBackStack(null);
						fragmentTransaction.replace(R.id.mainfragmentlayout,
								new Mysearch_SearchOption());
						fragmentTransaction.commit();

					}
				});

		view.findViewById(R.id.imgnearbyMysearch).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View v) {
						// create class object
				        gps = new GPSTracker(getActivity());

						// check if GPS enabled		
				        if(gps.canGetLocation()){
				        	
				        	
				        	double latitude = gps.getLatitude();
				        	double longitude = gps.getLongitude();
				           //calling  of nearby fragment 
				        	android.app.FragmentManager fragmentManager = getFragmentManager();
							android.app.FragmentTransaction fragmentTransaction = fragmentManager
									.beginTransaction();

							fragmentTransaction
									.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

							fragmentTransaction.addToBackStack(null);
							fragmentTransaction.replace(R.id.mainfragmentlayout,
									new MySearch_NearBy(latitude,longitude));
							fragmentTransaction.commit();

				        	
				        	
				        }else{
				        	// can't get location
				        	// GPS or Network is not enabled
				        	// Ask user to enable GPS/network in settings
				        	gps.showSettingsAlert();
				        }
						
						
						
						
						

					}
				});
		view.findViewById(R.id.imagemapMysearch).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						
						// create class object
				        gps = new GPSTracker(getActivity());

						// check if GPS enabled		
				        if(gps.canGetLocation()){
				        	
				        	double latitude = gps.getLatitude();
				        	double longitude = gps.getLongitude();
				        
				        	//startActivity(new Intent(getActivity(),MapFragmants.class));
				        	
				      //calling  of nearby fragment 
				        	
				        	android.app.FragmentManager fragmentManager = getFragmentManager();
							android.app.FragmentTransaction fragmentTransaction = fragmentManager
									.beginTransaction();

							fragmentTransaction
									.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

							fragmentTransaction.addToBackStack(null);
							fragmentTransaction.replace(R.id.mainfragmentlayout,
									new MapFragmants(latitude,longitude));
							fragmentTransaction.commit();
				        	
				        	
				        }else{
				        	// can't get location
				        	// GPS or Network is not enabled
				        	// Ask user to enable GPS/network in settings
				        	gps.showSettingsAlert();
				        }
						
						
						
						
						
						

						
						
					}
				});
		return view;
	}

}
